﻿<ResourceDictionary 
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:local="clr-namespace:DenisVuyka.Controls.PropertyGrid"
  xmlns:editors="clr-namespace:DenisVuyka.Controls.PropertyGrid.ValueEditors"
  xmlns:PropertyEditing="clr-namespace:Microsoft.Windows.Design.PropertyEditing;assembly=Microsoft.Windows.Design"
  xmlns:converters="clr-namespace:DenisVuyka.Controls.PropertyGrid.Converters"
  xmlns:controls="clr-namespace:DenisVuyka.Controls.PropertyGrid.Controls"
  x:Class="DenisVuyka.Controls.PropertyGrid.Resources.EditorResources">
  
  <converters:NullOrEmptyStringConverter x:Key="nullOrEmptyStringConverter"/>
  <converters:EnumValueConverter x:Key="enumValueConverter"/>
  <BooleanToVisibilityConverter x:Key="booleanToVisibilityConverter"/>
  
  <DataTemplate x:Key="DefaultValueEditorTemplate">
    <TextBox 
      x:Name="PART_editor"      
      Text="{Binding Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
      IsReadOnly="{Binding IsReadOnly}"/>
  </DataTemplate>
  
  <DataTemplate x:Key="DefaultEnumEditorTemplate">
    <controls:EnumDropdown
      x:Name="PART_editor"      
      Style="{DynamicResource {x:Type ComboBox}}"
      ItemsSource="{Binding ParentProperty.StandardValues}" 
      IsSynchronizedWithCurrentItem="False"
      SelectedValue="{Binding Value}" 
      IsEnabled="{Binding IsEditable}">
      <ComboBox.ItemTemplate>
        <DataTemplate>          
          <TextBlock Text="{Binding Path=., Converter={StaticResource enumValueConverter}}" />
        </DataTemplate>
      </ComboBox.ItemTemplate>
    </controls:EnumDropdown>
  </DataTemplate>
      
  <DataTemplate x:Key="DefaultBooleanEditorTemplate">
    <CheckBox x:Name="PART_editor" IsChecked="{Binding Value}" IsEnabled="{Binding IsEditable}" />
  </DataTemplate>
      
  <DataTemplate x:Key="DefaultFontFamilyEditorTemplate">
    <ComboBox 
      x:Name="PART_editor"      
      SelectedValue="{Binding Value}" 
      ItemsSource="{Binding Source={x:Static Fonts.SystemFontFamilies}}"
      IsEnabled="{Binding IsEditable}">
      <ComboBox.ItemTemplate>
        <DataTemplate>
          <TextBlock Text="{Binding}" FontFamily="{Binding}"/>
        </DataTemplate>
      </ComboBox.ItemTemplate>
    </ComboBox>
  </DataTemplate>

  <DataTemplate x:Key="NamedColorTemplate" DataType="{x:Type local:NamedColor}">
    <Grid>
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition Width="*"/>
      </Grid.ColumnDefinitions>
      <Rectangle Fill="{Binding Brush}" Grid.Column="0" Width="100" Height="20" Margin="2" HorizontalAlignment="Center"/>
      <TextBlock x:Name="PART_editor" Margin="5,2,2,2" Text="{Binding Name}" Grid.Column="1" HorizontalAlignment="Center"/>
    </Grid>
  </DataTemplate>

  <DataTemplate x:Key="DefaultBrushEditorTemplate">
    <ComboBox 
      x:Name="PART_editor"      
      Text="{Binding Path=Value, Mode=TwoWay, Converter={StaticResource nullOrEmptyStringConverter}}"
      ItemsSource="{Binding Source={x:Static local:EditorDataProvider.DefaultColorNames}}"
      ItemTemplate="{DynamicResource NamedColorTemplate}" 
      SelectedValuePath="Name"
      IsEditable="{Binding IsEditable}"
      IsEnabled="{Binding IsEditable}"/>
  </DataTemplate>
  
  <DataTemplate x:Key="DefaultXmlLanguageEditorTemplate">
    <ComboBox 
      x:Name="PART_editor"      
      SelectedValue="{Binding Value}" 
      ItemsSource="{Binding Source={x:Static local:EditorDataProvider.DefaultLanguages}}"
      IsEnabled="{Binding IsEditable}"
      />
  </DataTemplate>  
  
  <DataTemplate x:Key="FileBrowserInlineEditorTemplate">
    <Grid>
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="1*"/>
        <ColumnDefinition Width="Auto"/>
      </Grid.ColumnDefinitions>
      <TextBox Grid.Column="0" Text="{Binding StringValue}" IsReadOnly="True" />
      
      <PropertyEditing:EditModeSwitchButton        
        Grid.Column="1" 
        Margin="2,0,0,0" 
        Content="..." 
        Width="20"
        Style="{DynamicResource {x:Type Button}}"
        Visibility="{Binding IsEditable, Converter={StaticResource booleanToVisibilityConverter}}"
        />
    </Grid>
  </DataTemplate>
  
  <DataTemplate x:Key="SliderInlineEditorTemplate">
    <Slider x:Name="PART_editor"            
            Value="{Binding Value}"
            Minimum="{Binding ParentProperty.Metadata[NumberRange].Minimum, FallbackValue=0}"
            Maximum="{Binding ParentProperty.Metadata[NumberRange].Maximum, FallbackValue=100}" 
            TickFrequency="{Binding ParentProperty.Metadata[NumberRange].Tick, FallbackValue=1}"
            AutoToolTipPrecision="{Binding ParentProperty.Metadata[NumberRange].Precision, FallbackValue=0}" 
            AutoToolTipPlacement="BottomRight"
            IsDirectionReversed="False" 
            IsMoveToPointEnabled="True" 
            IsSnapToTickEnabled="False"
            IsEnabled="{Binding IsEditable}"
            />
  </DataTemplate>
  
  <DataTemplate x:Key="PasswordBoxInlineEditorTemplate">
    <PasswordBox 
      x:Name="PART_editor"
      local:PasswordBoxExtender.BindPassword="true"
      local:PasswordBoxExtender.BoundPassword="{Binding StringValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
      IsEnabled="{Binding IsEditable}"
      />
  </DataTemplate>

  <DataTemplate x:Key="DoubleInlineEditorTemplate">    
      <controls:DoubleEditor 
        x:Name="PART_editor"       
        Value="{Binding Value, Mode=TwoWay}"
        Minimum="{Binding ParentProperty.Metadata[NumberRange].Minimum}"
        Maximum="{Binding ParentProperty.Metadata[NumberRange].Maximum}"
        DefaultChange="{Binding ParentProperty.Metadata[NumberRange].Tick}"
        MaxPrecision="{Binding ParentProperty.Metadata[NumberRange].Precision}"
        IsEnabled="{Binding IsEditable}"
        />
  </DataTemplate>
  
</ResourceDictionary>